﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CodeAuto.Pages
{
    public partial class ThreeBlockCode : System.Web.UI.Page
    {

        public Models.T_Project project = null;
        public Models.T_Table table = null;
        public string ModelString = string.Empty;
        public string InterfaceString = string.Empty;
        public string ImplString = string.Empty;
        private List<Models.T_Field> fields = new List<Models.T_Field>();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.RegisterHyperLink.NavigateUrl = "/Pages/ProjectTables.aspx?docid=" + Request.QueryString["docid"];
            int tableid = Convert.ToInt32(Request.QueryString["tableid"]);
            int projectid = Convert.ToInt32(Request.QueryString["docid"]);
            DavidDB.ADO.DBManager db = new DavidDB.ADO.DBManager();
            project = new Models.T_Project();
            project.Id = projectid;
            project = db.GetModel(project);
            table = new Models.T_Table();
            table.Id = tableid;
            table = db.GetModel(table);
            Models.T_Field field = new Models.T_Field();
            field.TableId = tableid;
            var query = db.GetSomeObject(field);
            foreach (Models.T_Field f in query)
            {
                fields.Add(f);
            }
            fields = fields.OrderBy(a => a.Id).ToList();
            ModelString = DALS.TableDALS.GetModelString(project, table, fields);
            InterfaceString = DALS.TableDALS.GetInterfaceString(project, table);
            ImplString = DALS.TableDALS.GetImplString(project, table);
            db.Commit();
            db.Dispose();
        }

    }
}